# Maintainer: Alexandros Theodotou <alex at zrythm dot org>

_realname=lv2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-${_realname}-docs")
pkgver=1.18.10
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
pkgdesc='LV2 audio plugin specification (mingw-w64)'
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-python-lxml"
             "${MINGW_PACKAGE_PREFIX}-python-markdown"
             "${MINGW_PACKAGE_PREFIX}-python-pygments"
             "${MINGW_PACKAGE_PREFIX}-python-rdflib"
             "${MINGW_PACKAGE_PREFIX}-serd"
             "${MINGW_PACKAGE_PREFIX}-sord")
license=('spdx:ISC')
url="https://lv2plug.in/"
source=("https://lv2plug.in/spec/lv2-$pkgver.tar.xz"{,.sig}
        0001-meson-add-python-path.patch)
sha256sums=('78c51bcf21b54e58bb6329accbb4dae03b2ed79b520f9a01e734bd9de530953f'
            'SKIP'
            'a10a4094efd6b8f30deebd2c41412d8581f3391ec67c32a8e26e890af2891f3c')
validpgpkeys=('907D226E7E13FA337F014A083672782A9BF368F3') # David Robillard <d@drobilla.net>

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/0001-meson-add-python-path.patch"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  # Do not disable docs, it is coupled with lv2specgen
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/meson.exe \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Dplugins=disabled \
      -Dtests=disabled \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package_lv2() {
  optdepends=("${MINGW_PACKAGE_PREFIX}-lv2-docs: for developer documentation"
              "${MINGW_PACKAGE_PREFIX}-python-lxml: for lv2specgen.py"
              "${MINGW_PACKAGE_PREFIX}-python-markdown: for lv2specgen.py"
              "${MINGW_PACKAGE_PREFIX}-python-pygments: for lv2specgen.py"
              "${MINGW_PACKAGE_PREFIX}-python-rdflib: for lv2specgen.py"
              "${MINGW_PACKAGE_PREFIX}-sord: for lv2_validate")

  ${MINGW_PREFIX}/bin/meson.exe install -C "${srcdir}/build-${MSYSTEM}" --destdir "${pkgdir}"

  mkdir -p lv2-docs${MINGW_PREFIX}/share
  mv "${pkgdir}${MINGW_PREFIX}"/share/doc lv2-docs${MINGW_PREFIX}/share/doc

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}

package_lv2-docs() {
  pkgdesc+=" (documentation)"

  mv lv2-docs/* "${pkgdir}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
